package com.jdb.versailles.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.jdb.versailles.model.Client;
import com.jdb.versailles.service.ClientService;
// imports..
 
@Controller
public class ClientController {
   
  @Autowired 
  private ClientService clientService;
   
  @RequestMapping(value="/index" , method = RequestMethod.GET)
  public ModelAndView homePage(HttpServletResponse response) throws IOException{
//		Client client= new Client("RAKOTOVAO","HERISOA");
//		clientService.saveClient(client);		 
//		System.out.println("MON CLIENT : "+client.getNom() +" "+client.getPrenom());
		return new ModelAndView("index");
	}
  
  @RequestMapping(value="/clients" , method = RequestMethod.GET)
  public ModelAndView client(Map<String, Object> model) throws IOException{
	  Client client =new Client();
      model.put("client", client);
		return new ModelAndView("clients");
	}
  
  @RequestMapping(value="/addClients" , method = RequestMethod.POST)
  public ModelAndView saveClient(HttpServletResponse response,@ModelAttribute("client") Client client) throws IOException{
	  clientService.saveClient(client);
	  System.out.println("client sauvegardé");
		return new ModelAndView("clients");
	}
}
